package main

import (
	"feng-che.com/server/driver-quiz/api"
	"feng-che.com/server/driver-quiz/internal/cache"
	fiber_server_utils "fiberCommonUtils"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
	gofiberRecover "github.com/gofiber/fiber/v2/middleware/recover"
	"log"
	"os"
)

func main() {
	//初始化程序
	InitApp()
	cache.InitRedis()

	app := fiber.New(fiber.Config{
		ErrorHandler:       fiber_server_utils.CustomErrorHandle,
		Prefork:            false, // 定时任务子进程没有区分出来
		EnableIPValidation: true,
		ProxyHeader:        "X-Forwarded-For",
		//Views:        html.New("./views", ".html"),
	})
	app.Use(cors.New()) // 开发所有跨域
	app.Use(gofiberRecover.New())

	env := os.Getenv("ENV")

	// 安装必要的组件
	api.Route(app)

	switch env {
	default:
		log.Fatal(app.Listen(":" + os.Getenv("SERVER_PORT_NUMBER")))
	}
}
